// pages/salon/salon.js
import {
  getEndActivityList
} from '@/api/salon'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUri: getApp().globalData.imgUri,
    cdn: getApp().globalData.cdn,
    list:[
      {
        cnw:275,
        cnh:141,
        enw:211,
        enh:63
      },
      {
        cnw:346,
        cnh:141,
        enw:417,
        enh:103
      },
      {
        cnw:342,
        cnh:141,
        enw:485,
        enh:63
      },
      {
        cnw:275,
        cnh:141,
        enw:260,
        enh:63
      },
      {
        cnw:462,
        cnh:216,
        enw:520,
        enh:103
      },
    ],
    salon_list:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let t = this;
    getEndActivityList({}).then(res=>{
      if(res.code == 200){
        let timestamp = new Date().getTime();
        var data = res.data;
        for(var i=0;i<data.length;i++){
          var endtime_new = new Date(data[i].endTime).getTime();
          if(timestamp > endtime_new){
            data[i].is_activity_close = 1;
          }else{
            data[i].is_activity_close = 0;
          }
        }
        console.log(data);

        t.setData({
          salon_list:data
        })
      }
    });
  },
  goToDetail(e){
    let { id,endtime } = e.currentTarget.dataset;
    let timestamp = new Date().getTime();
    let endtime_new = new Date(endtime).getTime();
    if(timestamp > endtime_new){
      wx.navigateTo({
        url: '/pages/salonDetail/salonDetail?id='+id,
      });
    }else{
      wx.navigateTo({
        url: '/pages/salonInfo/salonInfo?id='+id,
      });
    }

  },
  onShareAppMessage() {
    return {
      title: getApp().globalData.share_title,
      path: getApp().globalData.share_url,
      imageUrl: getApp().globalData.share_image,
    }
  }
})